<?php if (! defined('APPPATH')) die('No direct script access allowed');
/**
 * RENARTI IK
 * An open source application development framework for PHP 5.2.0 or newer
 *
 * @package		RtiFramework
 * @author		Nauris Dambis <nauris.dambis@renarti.com>
 * @copyright	Copyright (c) 2012, RENARTI IK.
 * @license		http://renarti.com/#license
 * @link		http://renarti.com
 * @since		Version 1.0
 */

class RtiBenchmark
{
	private $_list = array();	
	
	/**
	 * Get execution time in seconds at current point of call in seconds
	 *
	 * @access	public
	 * @return	float
	 */
	public function microtime_float()
	{
	    list($usec, $sec) = explode(" ", microtime());
	    return ((float)$usec + (float)$sec);
	}
	
	/**
	 * Fix start time of entry
	 *
	 * @access	public
	 * @param	string $name
	 * @return	float
	 */
	public function start($name = 'undefined')
	{
		$this->_list[$name]['start'] = $this->microtime_float();
		return $this->_list[$name]['start'];
	}
	
	/**
	 * Fix end time of entry
	 *
	 * @access	public
	 * @param	string $name
	 * @return	float
	 */
	public function stop($name = 'undefined')
	{
		$this->_list[$name]['stop'] = $this->microtime_float();
		return $this->_list[$name]['stop'];		
	}
	
	/**
	 * Get entry execution time
	 *
	 * @access	public
	 * @param	string $name
	 * @return	float
	 */
	public function get($name = 'undefined')
	{
		if (! isset($this->_list[$name]['start']))
		{
			$this->start($name);
		}
		
		if (! isset($this->_list[$name]['stop']))
		{
			$this->stop($name);
		}
		
		return number_format(($this->_list[$name]['stop'] - $this->_list[$name]['start']), 4);
	}
}

/* End of file RtiBenchmark.php */
/* Location: ./system/core/RtiBenchmark.php */
